<template>
  <div class="index-container">
    <el-row :gutter="20">
      <el-col
        v-for="(item, index) in iconList"
        :key="index"
        :lg="6"
        :md="6"
        :sm="6"
        :xl="6"
        :xs="12"
      >
        <el-card class="icon-panel" shadow="hover">
          <div
            style="
              display: flex;
              flex-direction: column;
              align-items: center;
              justify-content: center;
            "
            @click="asfs(item)"
          >
            <el-badge :value="item.value">
              <vab-icon
                :icon="item.icon"
                :style="{ color: item.color, fontSize: '40px' }"
              />
            </el-badge>
            <p>{{ item.title }}</p>
          </div>
        </el-card>
      </el-col>

      <el-col :lg="24" :md="24" :sm="24" :xl="24" :xs="24"></el-col>
    </el-row>
    <el-row :gutter="20">
      <el-col :lg="24" :md="24" :sm="24" :xl="24" :xs="24">
        <el-card class="access" shadow="hover" skeleton>
          <div class="card-header" slot="header">
            <div>
              <vab-icon icon="tools-fill" />
              待保养设备清单
            </div>
          </div>
          <!-- <vab-query-form>
            <vab-query-form-left-panel :span="12"></vab-query-form-left-panel>
            <vab-query-form-right-panel :span="12">
              <el-form :inline="true" :model="queryForm" @submit.native.prevent>
                <el-form-item>
                  <el-input
                    v-model.trim="queryForm.MatchString"
                    clearable
                    placeholder="请输入"
                  />
                </el-form-item>
                <el-form-item>
                  <el-button
                    icon="el-icon-search"
                    type="primary"
                    @click="queryData"
                  >
                    查询
                  </el-button>
                </el-form-item>
              </el-form>
            </vab-query-form-right-panel>
          </vab-query-form> -->
          <el-table :data="list" style="width: 100%">
            <el-table-column label="保养编号" prop="Id" />
            <el-table-column label="设备编号" prop="DeviceId" />
            <el-table-column label="保养类型" prop="MainrenanceType" />
            <el-table-column label="保养周期" prop="Cycle" />
            <el-table-column label="负责人" prop="Director" />
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button
                  size="small"
                  @click="handleEdit(scope.$index, scope.row)"
                >
                  保养确认
                </el-button>
              </template>
            </el-table-column>
            <template slot="empty">
              <el-empty class="vab-data-empty" description="暂无数据" />
            </template>
          </el-table>
          <el-pagination
            background
            :current-page="queryForm.pageNo"
            :layout="layout"
            :page-size="queryForm.pageSize"
            :total="total"
            @current-change="handleCurrentChange"
            @size-change="handleSizeChange"
          />
        </el-card>
      </el-col>
    </el-row>

    <el-dialog
      :close-on-click-modal="false"
      :visible="dialogVisible"
      :title="title"
      width="60%"
      :before-close="handleClose"
    >
      <div>
        <el-table
          :data="FinishMainrenanceList"
          height="500"
          style="width: 100%"
        >
          <el-table-column label="保养编号" prop="Id" />
          <el-table-column label="设备编号" prop="DeviceId" />
          <el-table-column label="保养类型" prop="MainrenanceType" />
          <el-table-column label="保养周期" prop="Cycle" />
          <el-table-column label="保养时间" prop="StartTime" />
          <el-table-column label="负责人" prop="Director" />
          <template #empty>
            <el-empty class="vab-data-empty" description="暂无数据" />
          </template>
        </el-table>
        <el-pagination
          background
          :current-page="queryForm.pageNo"
          :layout="layout"
          :page-size="queryForm.pageSize"
          :total="total"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        />
      </div>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <!-- <el-button type="primary" @click="dialogVisible = false">
            确认
          </el-button> -->
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
  import {
    FinishMainrenance,
    WaitMainrenanceList,
    MainrenanceStatistics,
    OkButtonClick,
  } from '@/api/equipment'

  export default {
    data() {
      return {
        iconList: [
          {
            icon: 'timer-2-line',
            title: '今日待保养',
            link: '',
            color: '#95de64',
            type: 'ThisDayUnMaintain',
          },
          {
            icon: 'time-line',
            title: '今日已保养',
            link: '',
            color: '#69c0ff',
            type: 'ThisDayMaintain',
          },
          {
            icon: 'timer-line',
            title: '累计保养次数',
            link: '',
            color: '#ffd666',
            type: 'TotalMaintain',
          },
          {
            icon: 'map-pin-time-line',
            title: '本月已保养',
            link: '/other/player',
            color: '#ffc069',
            type: 'ThisMonthMaintain',
          },
        ],
        queryForm: {
          pageNo: 1,
          pageSize: 10,
          MatchString: '',
        },
        list: [],
        dialogVisible: false,
        Type: '',
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,

        tableData: [],
        title: '保养记录',
      }
    },
    created() {
      this.initData()
    },
    methods: {
      asfs(e) {
        this.dialogVisible = true
        this.Type = e.type
        this.a()
      },
      a() {
        const params = {
          Index: 0,
          Count: 100,
          Type: this.Type,
        }
        FinishMainrenance(params).then((res) => {
          console.log('待保养清单', res)
          this.FinishMainrenanceList = res.FinishMainrenanceList
        })
      },
      handleEdit(index, row) {
        OkButtonClick({ MainrenanceId: row.MainrenancePlanId }).then((res) => {
          console.log(res)
          this.initData()
        })
      },
      handleClose() {
        this.dialogVisible = false
      },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.getData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNo = val
        this.getData()
      },
      queryData() {
        this.queryForm.pageNo = 1
        this.fetchData()
      },
      fetchData() {
        this.listLoading = true
        const params = {
          Index: this.getPage(this.queryForm.pageNo, this.queryForm.pageSize),
          Count: this.queryForm.pageSize,
          MatchString: this.queryForm.MatchString,
        }
        WaitMainrenanceList(params).then((res) => {
          this.list = res.WaitMainrenanceList
          this.total = res.TotalCount
          this.listLoading = false
        })
      },
      getData() {
        //设备保养信息统计
        MainrenanceStatistics().then((res) => {
          this.iconList[0].value = res.TodayWaitMainrenance
          this.iconList[1].value = res.TodayFinishMainrenance
          this.iconList[2].value = res.TotalMainrenance
          this.iconList[3].value = res.ThisMonthMainrenance
        })
      },
      initData() {
        this.getData()
        this.fetchData()
      },
    },
  }
</script>

<style lang="scss" scoped>
  .index-container {
    padding: 0 !important;
    background: $base-color-background !important;

    :deep() {
      .access,
      .authorization,
      .version-information {
        min-height: 268px;
      }

      .el-card {
        .el-card__header {
          position: relative;

          .card-header-tag {
            position: absolute;
            top: 15px;
            right: $base-margin;
          }

          > div > span {
            display: flex;
            align-items: center;

            i {
              margin-right: 3px;
            }
          }
        }

        .el-card__body {
          position: relative;

          .echarts {
            width: 100%;
            height: 127px;
          }

          .card-footer-tag {
            position: absolute;
            right: $base-margin;
            bottom: 15px;
          }
        }
      }

      .bottom {
        padding-top: 20px;
        margin-top: 5px;
        color: #595959;
        text-align: left;
        border-top: 1px solid $base-border-color;
      }
    }
  }
</style>
